//Write a function f(a, b) which takes two character string arguments and 
//	returns a string containing only the characters found in both strings in the order of a. 
//	Write a version which is order N-squared and one which is order N.

#include <string>
#include <bitset>
#include <iostream>

std::string f(const std::string& a, const std::string& b) {
	std::bitset<128> table1,table2;
	std::string dup;
	for (std::string::const_iterator iter = a.begin(); iter!=a.end(); ++iter) {
		table1[*iter] = 1;
	}
	for (std::string::const_iterator iter = b.begin(); iter!=b.end(); ++iter) {
		table2[*iter] = 1;
	}
	for (std::string::const_iterator iter = a.begin(); iter!=a.end(); ++iter) {
		if (table1[*iter] == true && table2[*iter] == true) {
			dup.push_back(*iter);
			table1[*iter] = 0;
		}
	}
	std::cout << sizeof(table1) << std::endl;
	return dup;
}

void test_bitset() {
	std::string a,b;
	while(true) {
		std::cout << "enter string a:\n";
		std::cin >> a;
		std::cout << "enter string b:\n";
		std::cin >> b;
		std::string result = f(a,b);
		std::cout << result << std::endl;
	}
}